package com.chengdu.chun.service.impl;

import com.chengdu.chun.mapper.RoomMapper;
import com.chengdu.chun.po.Classes;
import com.chengdu.chun.po.Page;
import com.chengdu.chun.po.Room;
import com.chengdu.chun.service.RoomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RoomServiceImpl implements RoomService {

    @Autowired
    private RoomMapper roomMapper;

    @Override
    public Room getRoomByrid(int rid) {
        return roomMapper.getRoomByrid(rid);
    }

    @Override
    public Page<Room> getPageByroom(int page, int num) {
        int total = roomMapper.selectAllCountRoom();
        Page<Room> roomPage = new Page<>(page, num, total);
        if (total > 0) {
            List<Room> roomList = roomMapper.getRoomListBypage(
                    (roomPage.getCurpage() - 1) * roomPage.getNumber(),
                    roomPage.getNumber());
            roomPage.setDatalist(roomList);
        }
        return roomPage;
    }

    @Override
    public int selectCountRoom(int status) {
        return roomMapper.selectCountRoom(status);
    }

    @Override
    public List<Room> getRoomByName(String roomname) {
        return roomMapper.getRoomByName(roomname);
    }
}
